let Users = require('../models/Users');
let Roles = require('../models/Roles');
let Packages = require('../models/Packages');
let Applications = require('../models/Applications');
module.exports = function () {
    Users.getByName('admin',function (err,user) {
        if (err) {
            throw err;
        }
        if (!user) {
            let role = ({
                name : ' 管理员',
                permissions : {
                    packageA : true,
                    packageI : true,
                    managerA : true,
                    managerI : true
                }
            });
            Roles.createUniqueName(role,function (err,r) {
                if (err) {
                    throw err;
                } else {
                    var user = ({
                        username : 'admin',
                        nickname : '管理员',
                        email : 'admin',
                        passwd : 'admin',
                        role : r._id,
                        root : true
                    });
                    Users.createUnique(user,function (err) {
                        if (err) {
                            throw err;
                        }
                    });
                }
            });
        }
    });
    Applications.cleanArchiving();
    Packages.cleanArchiving();
};